<%--
  Created by IntelliJ IDEA.
  User: 熊自国
  Date: 2024/11/21
  Time: 11:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-L-admin1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/static/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/xadmin.css">
    <script src="${pageContext.request.contextPath}/static/js/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/layui/layui.js"
            charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body class="layui-anim layui-anim-up">
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">演示</a>
        <a>
          <cite>导航元素</cite></a>
      </span>
    <a class="layui-btn layui-btn-primary layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:38px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form id="f1" class="layui-form layui-col-md12 x-so"
              action="${pageContext.request.contextPath}/product/getMaterial.do" method="post">
            <input class="layui-input" placeholder="开始日" name="start" id="start" value="${start}">
            <input class="layui-input" placeholder="截止日" name="end" id="end" value="${end}">
            <input type="hidden" name="pageNum" id="pageNum">
            <input type="hidden" name="pageSize" id="pageSize">
            <input type="text" name="likename" placeholder="请输入原料名" autocomplete="off" class="layui-input"
                   value="${likename}">
            <button class="layui-btn" type="submit" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i>
            </button>
            <button class="layui-btn" id="re" type="button"><i class="layui-icon">清空</i>
            </button>
        </form>
    </div>
    <xblock>
        <%--        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>--%>
        <%--        <button class="layui-btn" onclick="x_admin_show('添加用户','./member-add.html',600,400)"><i class="layui-icon"></i>添加</button>--%>
        <span class="x-right" style="line-height:40px">当前第${Page.pageNum}页 总共${Page.pages}页，共${Page.total}条数据</span>
    </xblock>
    <c:if test="${sessionScope.user.deptId==null||sessionScope.user.deptId==2}">
        <button class="layui-btn" onclick="addGetMaterial()"><i class="layui-icon"></i>添加原料</button>
    </c:if>
    <table class="layui-table">
        <thead>
        <tr>
            <th>
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i
                        class="layui-icon">&#xe605;</i></div>
            </th>
            <th>原料获取编号</th>
            <th>原料名称</th>
            <th>原料数量</th>
            <th>创建时间</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach var="get" items="${Page.list}">
            <tr>
                <td>
                    <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i
                            class="layui-icon">&#xe605;</i></div>
                </td>
                <td>${get.getMaterialId}</td>
                <td>${get.materialName}</td>
                <td>${get.materialQuantity}</td>
                <td>
                    <fmt:formatDate value="${get.createAt}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate>
                </td>

                <c:choose>
                    <c:when test="${get.status == 0}">
                        <td>未接收</td>
                    </c:when>
                    <c:when test="${get.status == 1}">
                        <td>已接收</td>
                    </c:when>
                </c:choose>

                <c:if test="${sessionScope.user.deptId == 2}">
                    <td class="td-manage">
                        <c:if test="${get.status == 2}">
                            <a onclick="certainMaterial(${get.getMaterialId},${Page.pageNum})"
                               class="layui-btn layui-btn-sm layui-btn-primary"
                               href="javascript:;" title="确认收货">
                                确认收货
                            </a>
                        </c:if>
                            <%--                        <a title="分配部门" class="layui-btn layui-btn-sm layui-btn-normal"--%>
                            <%--                           onclick="toAllocationDept(${user.userId},${Page.pageNum})" href="javascript:;">--%>
                            <%--                            分配部门--%>
                            <%--                        </a>--%>
                            <%--                        <a class="layui-btn layui-btn-sm layui-btn-warm"--%>
                            <%--                           onclick="x_admin_show('修改密码','member-password.html',600,400)" title="修改密码"--%>
                            <%--                           href="javascript:;">--%>
                            <%--                            修改密码--%>
                            <%--                        </a>--%>
                            <%--                        <a title="删除" class="layui-btn layui-btn-sm layui-btn-danger"--%>
                            <%--                           onclick="member_del(this,'要删除的id')"--%>
                            <%--                           href="javascript:;">--%>
                            <%--                            删除--%>
                            <%--                        </a>--%>
                    </td>
                </c:if>
                <c:if test="${sessionScope.user.deptId == 5}">
                    <td class="td-manage">
                        <c:if test="${get.status == 0}">
                            <a id="confirm"
                               onclick="confirmOut(${get.materialId},${get.materialQuantity},${get.getMaterialId},${Page.pageNum})"
                               class="layui-btn layui-btn-sm layui-btn-primary"
                               href="javascript:;" title="确认出库 ">
                                确认出库
                            </a>
                        </c:if>
                            <%--<a title="分配部门" class="layui-btn layui-btn-sm layui-btn-normal"
                               onclick="toAllocationDept(${user.userId},${Page.pageNum})" href="javascript:;">
                                分配部门
                            </a>
                            <a class="layui-btn layui-btn-sm layui-btn-warm"
                               onclick="x_admin_show('修改密码','member-password.html',600,400)" title="修改密码"
                               href="javascript:;">
                                修改密码
                            </a>
                            <a title="删除" class="layui-btn layui-btn-sm layui-btn-danger"
                               onclick="member_del(this,'要删除的id')"
                               href="javascript:;">
                                删除
                            </a>--%>
                    </td>
                </c:if>


            </tr>
        </c:forEach>

        </tbody>
    </table>
    <div class="page">
        <div>
            <a href="javascript:go(1)" class="num">首页</a>
            <c:if test="${Page.hasPreviousPage}">
                <a class="prev" href="javascript:go('${Page.prePage}')">&lt;&lt;</a>
            </c:if>
            <c:choose>
                <c:when test="${Page.pages<=10}">
                    <c:set var="begin" value="1"></c:set>
                    <c:set var="end" value="${Page.pages}"></c:set>
                </c:when>
                <c:otherwise>
                    <c:set var="begin" value="${Page.pageNum-5}"></c:set>
                    <c:set var="end" value="${Page.pageNum+4}"></c:set>
                    <c:if test="${begin<1}">
                        <c:set var="begin" value="1"></c:set>
                        <c:set var="end" value="10"></c:set>
                    </c:if>
                    <c:if test="${end>Page.pages}">
                        <c:set var="begin" value="${Page.pages-9}"></c:set>
                        <c:set var="end" value="${Page.pages}"></c:set>
                    </c:if>
                </c:otherwise>
            </c:choose>
            <c:forEach var="i" begin="${begin}" end="${end}">
                <c:choose>
                    <c:when test="${Page.pageNum eq i}">
                        <span class="current">${i}</span>
                    </c:when>
                    <c:otherwise>
                        <a class="num" href="javascript:go(${i})">${i}</a>
                    </c:otherwise>
                </c:choose>
            </c:forEach>
            <%--            --%>
            <%--            <a class="num" href="">3</a>--%>
            <%--            <a class="num" href="">489</a>--%>
            <c:if test="${Page.hasNextPage}">
                <a class="next" href="javascript:go('${Page.nextPage}')">&gt;&gt;</a>
            </c:if>
            <a href="javascript:go(${Page.pages})" class="num">尾页</a>
        </div>
    </div>

</div>
<script>
    <%--$(document).ready(function() {--%>
    <%--   console.log(${sessionScope})--%>
    <%--});--%>


    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
    });

    /*用户-停用*/
    // function member_stop(obj, id) {
    //     layer.confirm('确认要停用吗？', function (index) {
    //
    //         if ($(obj).attr('title') == '启用') {
    //
    //             //发异步把用户状态进行更改
    //             $(obj).attr('title', '停用')
    //             $(obj).find('i').html('&#xe62f;');
    //
    //             $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
    //             layer.msg('已停用!', {icon: 5, time: 1000});
    //
    //         } else {
    //             $(obj).attr('title', '启用')
    //             $(obj).find('i').html('&#xe601;');
    //
    //             $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
    //             layer.msg('已启用!', {icon: 5, time: 1000});
    //         }
    //
    //     });
    // }

    /*用户-删除*/
    // function member_del(obj, id) {
    //     layer.confirm('确认要删除吗？', function (index) {
    //         //发异步删除数据
    //         $(obj).parents("tr").remove();
    //         layer.msg('已删除!', {icon: 1, time: 1000});
    //     });
    // }


    function delAll(argument) {
        var data = tableCheck.getData();
        console.log(data)
        var ids = ''
        for (var i = 0; i < data.length; i++) {
            ids += data[i] + '-'
        }
        console.log(ids)
        if (data.length > 0) {
            // layer.confirm('确定要删除吗？')
            //
            //
            //  layer.msg('删除成功', {icon: 1});
            layer.confirm('确认要删除吗？' + data, function (index) {
                window.location.href = "${pageContext.request.contextPath}/mate/delmate.do?ids=" + ids;
                layer.msg('删除成功', {icon: 1});
            });
        } else {
            layer.confirm('必须选择一个')
        }

    }

    function certainMaterial(id, pageNum) {
        window.location.href = "${pageContext.request.contextPath}/product/certainMaterial.do?getMaterialId=" + id + "&pageNum=" + pageNum;
    }

    function go(pageNum) {
        $("#pageNum").val(pageNum)

        $("#f1").submit();
    }


    function confirmOut(materialId, materialQuantity, getMaterialId, pageNum) {
        var ajax = new XMLHttpRequest();
        ajax.open("get", "${pageContext.request.contextPath}/warehouse/checkMaterialQuantity.do?materialId=" + materialId + "&materialQuantity=" + materialQuantity, true);

        ajax.send(null);

        ajax.onreadystatechange = function () {

            if (ajax.readyState === 4) {

                var str = ajax.responseText;

                if (str == "OK") {
                    window.location.href = "${pageContext.request.contextPath}/warehouse/confirmOut.do?materialId=" + materialId + "&materialQuantity=" + materialQuantity + "&getMaterialId=" + getMaterialId + "&pageNum=" + pageNum;
                } else if (str == "ERROR") {
                    alert("原料供给不足,请联系采购部门进行采购!")
                }
            }
        }
    }

    $("#re").click(function () {
        $("#like").val("")
        $(".layui-input").val("")
    })

    function addGetMaterial() {
        window.location.href = "${pageContext.request.contextPath}/product/addGetMaterial.do"
    }
</script>
</body>

</html>
